<?php

/*
 * transfert/index.phtml
 */
?>
<?php
$title = 'Transferts';
$this->headTitle($title);

// Variables
$site	 = $this->site;
$type	 = $this->type;
$refresh = $this->refresh;

// Tableau
$typeArray = array(
    '0'	 => 'Entrée et Sortie',
    '1'	 => 'Entrée',
    '2'	 => 'Sortie',
);
?>
<div class="content-head">
    <h3>
	<?php echo $title; ?> pour le site <a href="#" id="site" data-type="select"><?php echo $site->libelle ?></a> (<a href='#' id='type' data-type='select'><?php echo $typeArray[$type]; ?></a>)
	<img src='<?php echo $this->basePath() . '/img/rhx/refresh-16x16.png' ?>' title="Actualiser la liste" class='rhx-refresh'>
    </h3>
    <div class="toolbar">
	<div class="toggle add" title="Ajouter">
            <a href="<?php echo $this->url('RHX/default', array('controller'	 => 'transfert', 'action'	 => 'add')) ?>" style="display: block; width: 100%; height: 100%;"></a>
        </div>
    </div>
</div>

<div class="content-body">

    <!-- CONTENU AJAX -->
    <div id='content-data'>
	<!-- AJAX LOADING -->
    </div>
</div>

<form id="trasfertForm" action="#" method="post">
    <input type="hidden" id="data-site" name="site" value="<?php echo $site->id; ?>">
    <input type="hidden" id="data-type" name="type" value="<?php echo $type; ?>">
</form>

<script type="text/javascript">
    // Démarrage
    $(function(){
	// Editable Site
	$('#site').editable({
	    title: 'Liste des Sites',
	    source: '<?php echo $this->url('RHX/default', array('controller'	 => 'employe', 'action'	 => 'jsonSiteList')) ?>',
	    validate: function(value){
		$('#data-site').val(value);
		// Rafraichir
		refresh();
		changeSite(value);
	    }
	});

	// Editable Type
	$('#type').editable({
	    title: 'Liste des Choix',
	    source: [
              {value: 1, text: 'Entrée'},
              {value: 2, text: 'Sortie'}
           ],
	    validate: function(value){
		$('#data-type').val(value);
		// rafraichir
		refresh();
	    }
	});

	// Icone Rafraichir
	$('.rhx-refresh').click(function(e){
	    e.preventDefault();
	    // Rafraichir
	    refresh();
	});

	// Afficher
    <?php if ($refresh): ?>
    	    refresh();
    <?php endif; ?>
    });

    // Rafraichir la liste
    function refresh(){
	// Variables
	site = $('#data-site').val();
	type = $('#data-type').val();

	ajax = $.ajax({
	    type: 'post',
	    url : '<?php echo $this->url('RHX/default', array('controller'	 => 'transfert', 'action'	 => 'loadIndex')); ?>/' + site + '/' + type
	});
	ajax.error(function(){
	    alert('Une erreur est survenue');
	});
	ajax.success(function(data){
	    $('#content-data').hide().html('').html(data).fadeIn('fast');
	});

	return false;
    }
</script>